﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="gamelist.aspx.cs" Inherits="Website.gamelist" MasterPageFile="~/frag.Master" %>
<%@ MasterType VirtualPath="~/frag.Master" %>

<asp:content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Panel ID="Panel2" runat="server" HorizontalAlign="Center">
    
    <div>
        Welcome 
        <asp:Label ID="lblUserName" runat="server" Text="" ></asp:Label>!<br />
        Your score is:
        <asp:Label ID="lblScore" runat="server"></asp:Label>
        <br />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="logout.aspx">Sign out</asp:HyperLink>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        
        
        <asp:UpdatePanel ID="UpnlGames" runat="server" UpdateMode="Conditional">
        <ContentTemplate>

    <asp:Panel ID="Panel1" runat="server" GroupingText="Current games">
            <table style="border: solid 1px black;" align="center">
                <asp:Repeater ID="GamesRepeater" runat="server" OnItemCommand="GamesRepeater_OnItemCommand" EnableViewState="false">
                <HeaderTemplate>
                    <thead>
                    <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Number of players</th>
                    <th>Board Size</th>
                    </tr>
                    </thead>
                </HeaderTemplate>
                <ItemTemplate>
                <tr>
                <td>
                    <asp:Button ID="ButtonJoin" runat="server" Text="Join" CommandName="Join" CommandArgument='<%# Eval("Name") %>' Enabled = '<%# !((bool)Eval("isPlaying")) %>' EnableViewState="false" /></td>
                <td><%# Eval("Name") %></td>
                <td><%# ((bool)Eval("isPlaying"))?Eval("NTotalPlayers"):Eval("NCurrentPlayers")%>/<%# Eval("NTotalPlayers")%></td>
                <td><%# Eval("Rows")%>x<%# Eval("Cols")%></td>
                </tr></ItemTemplate>
                </asp:Repeater>
                
              
                
            </table>
                  <asp:Timer ID="Timer1" runat="server" Enabled="False" Interval="3000" 
                    ontick="Timer1_Tick">
                </asp:Timer>
            </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>
             
        
    
    
        <asp:Panel ID="PanelCreate" runat="server" GroupingText="Create a new game" 
            HorizontalAlign="Center">
            <table align="center">
                <tr>
                    <td>
                        Name</td>
                    <td>
                        <asp:TextBox ID="TextName" runat="server"></asp:TextBox>
                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Name is required" Text="*" ControlToValidate="TextName" ValidationGroup="CreateGroup"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Number of players</td>
                    <td>
                        <asp:TextBox ID="TextNPlayers" runat="server"></asp:TextBox>
                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Number of players is required" Text="*" ControlToValidate="TextNPlayers" Display="Dynamic" ValidationGroup="CreateGroup"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Number of players must be valid integer between 2-9" Text="*" ControlToValidate="TextNPlayers" Display="Dynamic" MinimumValue="2" MaximumValue="9" Type="Integer" ValidationGroup="CreateGroup"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Rows in board</td>
                    <td>
                        <asp:TextBox ID="TextRows" runat="server"></asp:TextBox>
                    </td>
                    <td align="center">
                        <asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="Rows must be valid integer between 5-16 (or empty for default)" Text="*" ControlToValidate="TextRows" Display="Dynamic" MinimumValue="5" MaximumValue="16" Type="Integer" ValidationGroup="CreateGroup"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Columns in board</td>
                    <td>
                        <asp:TextBox ID="TextColumns" runat="server"></asp:TextBox>
                    </td>
                    <td>
                        <asp:RangeValidator ID="RangeValidator3" runat="server" ErrorMessage="Columns must be valid integer between 5-20 (or empty for default)" Text="*" ControlToValidate="TextColumns" Display="Dynamic" MinimumValue="5" MaximumValue="20" Type="Integer"></asp:RangeValidator>
                    </td>
                </tr>
            </table>
            <asp:Button ID="ButtonCreate" runat="server" Text="Create!" 
                onclick="ButtonCreate_Click" ValidationGroup="CreateGroup"/>
            
        </asp:Panel>
        <asp:Label ID="LabelMessage" runat="server" Text="Message" Visible="false" ForeColor="Red"></asp:Label>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please fix the following errors:"/>
    </div>
    </asp:Panel>
</asp:content>